﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessInventoryInfoSel
// 文件功能描述：食材库存查询数据访问层
//
// 
// 创建标识：2012-04-01 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessInventoryInfoSel
    {
        /// <summary>
        /// 主副调食材库存数量
        /// </summary>
        /// <returns></returns>
        public int GetInventoryInfoSelCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from CON_Goods_Stocks_View";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取副调食材库存信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelInventoryInfoSelInfo(int pagesize, int startindex, string strquery, string Warehouse_ID, out int count)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                //string query = "select * from (select ROW_NUMBER() OVER(ORDER BY GOODSNO ASC) rownumber,* " +
                //               "from CON_Goods_Stocks_View where STOCKS_COUNT!=0 " + strquery + ") B "
                //             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                //DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                //return ds;
                SqlParameter[] parameters = {
                    new SqlParameter("@Warehouse_ID", SqlDbType.Int),
                    new SqlParameter("@Where", SqlDbType.VarChar,100),
                    new SqlParameter("@startrow",SqlDbType.Int),
                    new SqlParameter("@endrow", SqlDbType.Int)
                    };
                parameters[0].Value = Warehouse_ID;
                parameters[1].Value = strquery;
                parameters[2].Value = startrow;
                parameters[3].Value = endrow;
                DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.StoredProcedure, "Proc_CON_GOODS_STOCKS", parameters);
                count = ds.Tables[0].Rows.Count;
                return ds;
            }
        }
    }
}
